using UnityEngine;

namespace Pvp.Ecs
{
    public abstract class IDataComponent
    {
        public int BelongEntityId { get; set; }

        public bool TryGetCombineComponent<T>(out T value) where T : IDataComponent
        {
            value = null;
            var components = Entities.GetComponents<T>();
            foreach (var com in components)
            {
                if (com.BelongEntityId == BelongEntityId)
                {
                    value = com;
                    break;
                }
            }
            return value != null;
        }

        public T GetSingleComponent<T>() where T : ISingleDataComponent
        {
            return Entities.GetSingleComponent<T>();
        }
    }
}